import { createSSRApp } from "vue";
import App from "./App.vue";
import {
  UNI_STORAGE_KEY_TOKEN,
  UNI_STORAGE_KEY_USER_PROFILE,
} from "@/utils/constants";

export function createApp() {
  const app = createSSRApp(App);

  app.config.errorHandler = (err, vm, info) => {
    if (err?.data?.errorCode == "Auth_Exception_0005") {
      // 前端取消授权
      uni.removeStorageSync(UNI_STORAGE_KEY_USER_PROFILE);
      uni.removeStorageSync(UNI_STORAGE_KEY_TOKEN);
      // 跳转至登录页
      uni.switchTab({
        url: "/pages/login/login",
      });
    }
  };

  return {
    app,
  };
}
